package org.msfj.common.model;


import java.io.Serializable;

/**
 * 淘淘商城自定义响应结构
 */
public class CommonResult<T> implements Serializable {

    public static final int OK = 200;

    // 响应业务状态
    private Integer httpCode;

    // 响应消息
    private String msg;

    // 响应中的数据
    private T data;

    public static CommonResult build(Integer httpCode, String msg, Object data) {
        return new CommonResult(httpCode, msg, data);
    }

    public static CommonResult ok(Object data) {
        return new CommonResult(data);
    }

    public static CommonResult ok() {
        return new CommonResult(null);
    }

    public static CommonResult error(String msg) {
        return new CommonResult(500, msg, null);
    }

    public CommonResult() {

    }

    public static CommonResult build(Integer status, String msg) {
        return new CommonResult(status, msg, null);
    }

    public CommonResult(Integer httpCode, String msg, T data) {
        this.httpCode = httpCode;
        this.msg = msg;
        this.data = data;
    }

    public CommonResult(T data) {
        this.httpCode = OK;
        this.msg = "OK";
        this.data = data;
    }

    public Integer getHttpCode() {
        return httpCode;
    }

    public void setHttpCode(Integer httpCode) {
        this.httpCode = httpCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * 是否是正常返回
     *
     * @return
     */
    public boolean isOK() {
        return this.httpCode == OK;
    }

    /*抽号系统判断的返回结果是使用 status 属性*/
    public Integer getStatus() {
        return httpCode;
    }


}
